from httprequest import HttpRequest
from readexcel import ReadExcel
from writeexcel import WriteExcel

class Run:
    def __init__(self,result):
        self.result=result
        self.http_request_obj = HttpRequest("http://接口头部")  # 生成一个http请求实例
        self.write_result=WriteExcel()

    def run(self):
        for i in range(len(self.result)):
            test_data = self.result[i]  # 对列表的每个元素进行拆分，拆分后又是列表格式
            url = test_data[0]       #接在头部后面行成完整的url地址
            excel表中的参数2 = str(test_data[1])
            excel表中的参数3 = int(test_data[2])
            http_method = test_data[3]
            recharge_data = {"表头2": excel表中的参数2, "表头3": excel表中的参数3}
            if http_method == "GET":
                request_result = self.http_request_obj.get(url, recharge_data)
            elif http_method == "POST":
                request_result = self.http_request_obj.post(url, recharge_data)
            else:
                print("请求数据错误")
            self.write_result.write_excel(i,request_result)
        self.write_result.save_excel()

result=ReadExcel().read_excel()
run_result=Run(result)
run_result.run()